<template>
    <div>
        <table class="table">
            <tbody>
                <tr>
                    <td>姓名</td>
                    <td>

                        <input type="text" v-model="date.memberName">
                    </td>
                </tr>
                <tr>
                    <td>编号</td>
                    <td>
                        <select v-model="date.memberLevelId">
                            <option value="0">请选择</option>
                            <option value="1">妇科</option>
                            <option value="2">精神科</option>
                            <option value="3">肛门科</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>图片</td>
                    <td>
                        <input type="file" @change="upload">
                        <img :src="'https://localhost:7201/'+date.img" width="60px" height="60px">
                    </td>
                </tr>
                <tr>
                    <td>日期</td>
                    <td>
                        <input type="date" v-model="date.creates">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="button" value="新增" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
const routher = useRouter()
const upload=(e:any)=>{
    var a = e.target.files[0]
    var aa = new FormData()
    aa.append("file",a)

    if(a.size>1024*1024*2){
        alert("格式大小只能是2MB")
        return
    }
    axios.post("https://localhost:7201/api/UpLoad/UpFile",aa).then(res=>{
        date.value.img=res.data
        alert("上传成功")
    })
}
const add=()=>{
    if(date.value.memberName==""){
        alert("姓名不能为空")
        return
    }
    axios.post("https://localhost:7201/api/Member/AddMember",date.value).then(res=>{
        if(res.data>0){
            alert("新增成功")
            routher.push({path:"/Show"})
        }
        else{
            alert("新增失败")
        }
    })
}
const date=ref({
  "memberId": 0,
  "memberName": "",
  "img": "",
  "memberLevelId": 0,
  "creates": ""
})
</script>

<style scoped>

</style>